package controller.gui.menubar;

import gui.MapEditorFrame;

import java.awt.event.ActionEvent;

import javax.swing.JFileChooser;
import javax.swing.JMenuItem;

import controller.AbstractSaveMenuBarController;
import controller.BrowseUser;
import controller.Controller;
import controller.MenuBarController;
import controller.NullStaticObjectException;

public final class SaveMapController extends AbstractSaveMenuBarController implements BrowseUser{

	public SaveMapController(MapEditorFrame _frame,JMenuItem towire){
		super(_frame,towire);
	}
	
	@Override
	public void wizardInizializer(ActionEvent arg0)throws NullStaticObjectException {
		if (this.toBeSavedWithSaveAs.getValue()){//salva con nome...
			this.filechooser.setFileFilter(DIRECTORYMDMAPFILTER);
			int userchoice=this.filechooser.showSaveDialog(this.frame);
			if (userchoice==JFileChooser.APPROVE_OPTION){
				this.saveMap(this.filechooser.getSelectedFile().getAbsolutePath(),Controller.getCurrentmap());
			}
		}else{//salva velocemente
			this.saveMap(this.saveHandler.getTheFile().getAbsolutePath(),Controller.getCurrentmap());
		}
		this.setToIdle();
	}

}
